/*
 * Copyright (c) 2021
 * User:mallplus多商户商城
 * File:OmsBillingRecordsController.java
 * Date:2021/01/12 19:29:12
 */

package com.qyine.rlmall.oms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qyine.rlmall.annotation.SysLog;
import com.qyine.rlmall.oms.entity.OmsBillingRecords;
import com.qyine.rlmall.oms.vo.QueryBillCriteria;
import com.qyine.rlmall.utils.CommonResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author mallplus
 * @date 2020-11-11
 * 账单记录
 */
@Slf4j
@RestController
@RequestMapping("/oms/omsBillingRecords")
public class OmsBillingRecordsController {

    @Resource
    private com.qyine.rlmall.oms.service.IOmsBillingRecordsService IOmsBillingRecordsService;

    @SysLog(MODULE = "oms", REMARK = "根据条件查询所有账单记录列表")
    @ApiOperation("根据条件查询所有账单记录列表")
    @GetMapping(value = "/storebillings")
    @PreAuthorize("hasAuthority('oms:omsBillingRecords:read')")
    public Object storebillings(QueryBillCriteria entity) {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("storeName", entity.getStoreName());
            params.put("startTime", entity.getStartTime());
            params.put("endTime", entity.getEndTime());
            params.put("storeId", entity.getStoreId());
            params.put("status", entity.getStatus());
            return new CommonResult().success(IOmsBillingRecordsService.queryStoreBillings(params));
        } catch (Exception e) {
            log.error("根据条件查询所有账单记录列表：%s", e.getMessage(), e);
        }
        return new CommonResult().failed();
    }

    @SysLog(MODULE = "oms", REMARK = "根据条件查询所有账单记录列表")
    @ApiOperation("根据条件查询所有账单记录列表")
    @GetMapping(value = "/list")
    @PreAuthorize("hasAuthority('oms:omsBillingRecords:read')")
    public Object getOmsBillingRecordsByPage(OmsBillingRecords entity,
                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        try {
            return new CommonResult().success(IOmsBillingRecordsService.page(new Page<OmsBillingRecords>(pageNum, pageSize), new QueryWrapper<>(entity)));
        } catch (Exception e) {
            log.error("根据条件查询所有账单记录列表：%s", e.getMessage(), e);
        }
        return new CommonResult().failed();
    }
    /**
     * 设置店铺对账记录状态为已结算
     *
     * @param ids 对账记录id数组
     * @return 成功>=1 否则失败
     */
    @PutMapping("/storebillingrecord")
    @ApiOperation(value = "设置店铺对账记录状态为已结算", notes = "设置店铺对账记录状态为已结算（需要认证）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "array", name = "ids", value = "对账记录id数组"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功>=1 否则失败", response = Integer.class)
    })
    public Object updateStoreBillingRecordStatus(Long[] ids) {
        return new CommonResult().success(IOmsBillingRecordsService.updateStatus(ids));
    }

}


